package org.xxmi.cors.web;


import org.springframework.web.bind.annotation.*;
import org.xxmi.cors.model.Form;

/**
 *      * 测试工具：Postman
 */
@RequestMapping("/form")
@RestController
public class FormControl {


    @GetMapping("/test")
    public String test() {
        return "success";
    }

    /**
     * 请求方式：http://localhost:8801/form?ids=1,2,3
     */
    @GetMapping
    public Form getForm(Form form) {
        System.out.println(form);
        return form;
    }

    /**
     * 请求方式：http://localhost:8801/form/json
     * Body:{
     *      "ids":[1,2,3],
     *      "names":["Chen"]
     * }
     */
    @GetMapping("/json")
    public Form getFormJson(@RequestBody Form form) {
        System.out.println(form);
        return form;
    }

    /**
     * TODO 这个是错误的写法
     */
    @GetMapping("/request/param/entity")
    public Form getFormRequestParam(@RequestParam Form form) {
        System.out.println(form);
        return form;
    }

    /**
     * 请求方式：http://localhost:8801/form/request/param?name=Chen
     */
    @GetMapping("/request/param")
    public String getFormRequestParam(@RequestParam String name) {
        System.out.println(name);
        return name;
    }

    /**
     * 请求方式：http://localhost:8801/form/json
     * Body:{
     *      "ids":[1,2,3],
     *      "names":["Chen"]
     * }
     */
    @PostMapping
    public Form postForm(@RequestBody Form form) {
        System.out.println(form);
        return form;
    }
}
